package com.imooc.bilibili.domain;

import lombok.Data;

/**
 * ProjectName imooc-bilibili
 *
 * @author xieyucan
 * <br>CreateDate 2022/10/21 17:22
 */
@Data
public class JsonResponse<T> {
    private String code;

    private String msg;

    private T data;

    public JsonResponse(String code,String msg)
    {
        this.code=code;
        this.msg=msg;
    }

    public JsonResponse(T data)
    {
        this.data=data;
        this.msg="成功";
        this.code="0";
    }

    /**
     * 没有数据传输的返回成功
     * @return
     */
    public static JsonResponse success()
    {
        return new JsonResponse(null);
    }

    /**
     * 带有数据的成功统一返回
     * @param data
     * @return
     */
    public static JsonResponse success(String data)
    {
        return new JsonResponse(data);
    }

    public static JsonResponse fail()
    {
        return new JsonResponse("1","失败");
    }

    public static JsonResponse fail(String code,String msg)
    {
        return new JsonResponse(code,msg);
    }
}
